package ai.mspbots.test.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

import java.net.InetSocketAddress;
import java.net.Proxy;

@Configuration
public class AppConfig {
    @Bean
    public RestTemplate restTemplate() {
        // 创建请求工厂
        SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();

        // 设置代理 (HTTP 代理，地址为 127.0.0.1，端口为 7890)
        Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 7890));
        factory.setProxy(proxy);

        // 可选：设置超时时间
        factory.setConnectTimeout(5000); // 连接超时 5秒
        factory.setReadTimeout(10000);   // 读取超时 10秒

        return new RestTemplate(factory);
    }
}